<template>
  <el-dialog :title="dialogProps.title" :visible.sync="dialogProps.visible" width='600px'  append-to-body  :fullscreen = 'Global.currentDevice'>
        <!-- table -->
        <el-table   :data="tableList" style="width: 100%"  :cell-class-name='hover'  @cell-click='checkUser'>
              <el-table-column prop="title"    label="名称"    >
                    <template slot-scope="scope">
                          <el-link type="info"  v-if='scope.row.viewFlag == 1'>{{scope.row.title}}</el-link>
                          <el-link type="primary"  v-else>{{scope.row.title}}</el-link>
                    </template>
              </el-table-column>
              <el-table-column prop="createTime"  label="更新时间" align="center">
                      <template slot-scope="scope">
                          {{scope.row.createTime | formatDate}}
                      </template>
              </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination class='mt28  mb28'  align='center'
                background
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="1"
                
                :page-size="5"
                :pager-count="5"
                :hide-on-single-page='true'
                layout="total, prev, pager, next, jumper"
                :total="Total">
        </el-pagination>
        <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="dialogProps.visible=false">确 定</el-button>
        </div>
  </el-dialog>
</template>

<script charset="utf-8" type="text/javascript">
import  {  ListMessge,AlreadyRead  }  from  '@/api/homework/index'
export default {
  name: 'MyMessage',
  data() {
    return {
      loading: false,
      //dialogo基本信息  显示隐藏状态  title 
      dialogProps: {
        visible: false,
        action: '',
        title: '我的消息'
      },
      form:{

      },
      search:{
        limit:5,
        currentPage:1
      },
      tableList:[],
      Total:null,

    }
  },
  created(){
    
    
    
  },
  methods: {
      pageInit(){
        ListMessge(this.search).then(res=>{
          if(res.data.flag == true){
              this.tableList = res.data.dataList
              this.Total = res.data.totalRs
          }
        }).catch(error=>{
          console.log(error)
        })
      },
      hover({row, column, rowIndex, columnIndex}){
      //console.log(row, column, rowIndex, columnIndex)
      //设置表格第一列的特殊样式  该样式需要在APP 或者 public.css设置
        // if(columnIndex == 0  && row.viewFlag == 0){
        //   return 'activeCol'
        // }
      },
      //点击表格第一列  查看详情
      checkUser(row, column, cell, event){
          if(column.label == '名称'){
              AlreadyRead(row.code).then(res=>{
                  if(res.data.flag == true){
                      let mesnum ;
                      ListMessge({pageNo:1,pageSize:10}).then(res1=>{
                          if(res1.data.flag == true){
                              mesnum = res1.data.notViewCount
                              this.$store.commit("setmessageNum",mesnum);
                          }
                      }).catch(error=>{
                          console.log(error)
                      })
                      if(row.referType<5){
                        /*访问同一个路由，只不过带的参数不同时：访问的路由只会created一次，需要监听路由变化来实现页面数据变化*/
                          this.$router.push({path:'/examine/detail',query:{code:row.referCode,isCheck:'true',type:row.referType}})
                      }
                      else if(row.referType == 5){
                          this.$router.push({path:'/company'})
                      }
                      else if(row.referType == 6){
                          this.$router.push({path:'/project'})
                      }
                      else if(row.referType == 7){
                          this.$router.push({path:'/product'})
                      }
                      
                      this.dialogProps.visible= false
                  }
              }).catch(error=>{
                console.log(error)
              })
              // this.$router.push({name:'project_Detail',params:{code:row.code}})
              
          }
      },
      /*每页显示条数变化 事件触发*/
      handleSizeChange(val) {
        this.search.limit = val;
        this.pageInit()
      },
      /*页数变化 事件触发*/
      handleCurrentChange(val) {
        this.search.currentPage = val
        this.pageInit()
      },
  },
  mounted: function() {
    this.$nextTick(() => {
      this.$on('openDialog', function() {
        
        this.pageInit()
        this.dialogProps.visible = true
        
      })
      
    })
  },
  updated(){
    
  },
  components:{
    
  }
}
</script>

<style  scoped>
</style>
